<template>
  <div class="examination-suggestion">
    <h3 class="section-title">相关检查建议</h3>
    
    <el-collapse v-model="activeNames" @change="handleChange">
      <el-collapse-item
        v-for="exam in examinations"
        :key="exam.id"
        :name="exam.id"
      >
        <template #title>
          <div class="exam-header">
            <el-icon><Document /></el-icon>
            <span class="exam-name">{{ exam.name }}</span>
            <el-tag size="small" type="info" style="margin-left: 12px;">
              匹配度 {{ getRandomMatchRate() }}%
            </el-tag>
          </div>
        </template>
        
        <div class="exam-details">
          <div class="detail-row">
            <div class="detail-label">检查目的：</div>
            <div class="detail-content">{{ exam.purpose }}</div>
          </div>
          
          <div class="detail-row">
            <div class="detail-label">注意事项：</div>
            <div class="detail-content">{{ exam.notice }}</div>
          </div>
          
          <div class="detail-row">
            <div class="detail-label">检查流程：</div>
            <div class="detail-content">{{ exam.process }}</div>
          </div>
          
          <div class="detail-row">
            <div class="detail-label">检查地点：</div>
            <div class="detail-content">{{ exam.location }}</div>
          </div>
          
          <div class="exam-actions">
            <el-button type="primary" @click="makeAppointment(exam)">
              预约检查
            </el-button>
            <el-button @click="viewDetails(exam)">
              查看详情
            </el-button>
          </div>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElCollapse, ElCollapseItem, ElIcon, ElTag, ElButton, ElMessage } from 'element-plus'
import { Document } from '@element-plus/icons-vue'

const props = defineProps({
  examinations: {
    type: Array,
    required: true
  }
})

const emit = defineEmits(['view-examination'])

const activeNames = ref([])

const handleChange = (val) => {
  console.log('折叠面板变化:', val)
}

// 生成随机匹配度（模拟数据）
const getRandomMatchRate = () => {
  return Math.floor(Math.random() * 30) + 70 // 70-99%
}

// 预约检查
const makeAppointment = (examination) => {
  ElMessage.success(`已为您预约${examination.name}，请按时检查`)
  console.log('预约检查:', examination)
}

// 查看详情
const viewDetails = (examination) => {
  emit('view-examination', examination)
}
</script>

<style scoped>
.examination-suggestion {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.section-title {
  margin: 0 0 20px 0;
  font-size: 18px;
  color: #333;
}

.exam-header {
  display: flex;
  align-items: center;
}

.exam-header .el-icon {
  margin-right: 10px;
  color: #409eff;
}

.exam-name {
  font-weight: 500;
  font-size: 16px;
}

.exam-details {
  padding: 16px 0;
}

.detail-row {
  display: flex;
  margin-bottom: 16px;
}

.detail-row:last-child {
  margin-bottom: 0;
}

.detail-label {
  width: 100px;
  font-weight: 500;
  color: #666;
}

.detail-content {
  flex: 1;
  color: #333;
}

.exam-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}
</style>